package com.wqtz.chechai.view.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.wqtz.chechai.R;
import com.wqtz.chechai.adapter.AdSearchStatusAdapter;
import com.wqtz.chechai.adapter.SearchResultAdapter;
import com.wqtz.chechai.base.BaseActivity;
import com.wqtz.chechai.bean.MsgBean;
import com.wqtz.chechai.bean.OrderBean;
import com.wqtz.chechai.presenter.BasePresent;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称： CheChai
 * 创建人 : Liberation
 * 创建时间: 2017/2/22 17:02
 */

public class SearchResultActivity extends BaseActivity implements SearchResultAdapter.QuoteItemClickCallBack {
	/*
	* 四种状态
	* 0：审核通过
	* 1：审核中
	* 2：拒绝
	* 3：取消审核*/
	private final int PASS = 0;
	private final int REVIEW = 1;
	private final int REFUSE = 2;
	private final int CANCLE = 3;
	@BindView(R.id.iv_back)
	ImageView mIvBack;
	@BindView(R.id.tv_title)
	TextView mTvTitle;
	@BindView(R.id.lv)
	ListView mLv;


	private List<String> datas;
	private int mHour = 3;
	private int mMinuts = 05;
	int requsetNum = 0;
	private int statusType;//状态类型
	private int timeType;//时间类型
	List<OrderBean> data;//模拟数据
	private SearchResultAdapter searchAdapter;

	@Override
	public void init() {
		ButterKnife.bind(this);
		data = new ArrayList<>();
		searchAdapter = new SearchResultAdapter(R.layout.item_search_result);
		searchAdapter.setClickListen(this);
		mLv.setAdapter(searchAdapter);
		Intent intent = getIntent();
		statusType = intent.getIntExtra("statusType", 0);
		timeType = intent.getIntExtra("timeType", 0);
		createData(12, false, "宝马");


	}

	@Override
	public void loadData() {

	}

	@Override
	public int setContentViews() {
		return R.layout.activity_searchresult;
	}

	@Override
	public BasePresent createPresenter() {
		return null;
	}

	/**
	 * @param request    请求的条数
	 * @param isResfresh 是否刷新
	 * @param carName    车辆名字仅做测试
	 */
	private void createData(int request, boolean isResfresh, String carName) {
		data.clear();
		if (isResfresh) {
			requsetNum = 15;
		} else {
			requsetNum += request;
		}
		for (int i = 0; i < requsetNum; i++) {
			//		Logger.e(requsetNum + "请求的数据量");
			OrderBean d = new OrderBean();
			d.setCarVIN("1F2B5D888FA44FRT" + i % 10);
			switch (statusType){
				case 0 :{
					d.setType(i%4);
				}break;
				case 1:{
					d.setType(REVIEW);
				}break;
				case 2:{
					d.setType(PASS);
				}break;
				case 3:{
					d.setType(REFUSE);
				}break;

			}

			d.setVisible(true);//是否可见
			d.setCarModel(carName + String.valueOf(i));
			d.setCarBuyTime("6年" + String.valueOf(i % 12) + "个月");
			d.setMileage(String.valueOf(i + 20) + "km");
			d.setCarStatus("一抵");
			d.setAssumPrice(20 + i + "万");
			d.setShouldPay((20 + i - 3) + "万");
			d.setPrice1(20 + i + "");
			d.setPrice2(21 + i + "");
			d.setPrice3(22 + i + "");
			d.setLastModefyTime("15.20"+i);
			List<MsgBean> msgs = new ArrayList<>();
			for (int j = 0; j < 2; j++) {
				MsgBean msgBean = new MsgBean();
				msgBean.time = "   2016-9-" + i % 30 + " 12:55:12";
				msgBean.title = "【张婷】已审核了该报价，价格调整为" + (10 + i) + "万元";
				msgs.add(msgBean);
			}
			d.setMsgs(msgs);
			data.add(d);
		}
		searchAdapter.clearData();
		searchAdapter.addData(data);

	}


	@OnClick({R.id.iv_back})
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.iv_back:
				finish();
				break;

		}
	}

	@Override
	public void oItemClickItem(int position) {
		Intent intent = new Intent(this, QuoteDetailActivity.class);
		OrderBean o = data.get(position);
		intent.putExtra("cityId", o.getCityId());
		intent.putExtra("provinceId", o.getProvinceId());
		intent.putExtra("carModelId", o.getCarModelId());
		intent.putExtra("carModel", o.getCarModel());
		intent.putExtra("buyTime", o.getCarBuyTime());
		intent.putExtra("mileage", o.getMileage());
		intent.putExtra("carStatus", o.getCarStatus());
		intent.putExtra("price1", o.getPrice1());
		intent.putExtra("price2", o.getPrice2());
		intent.putExtra("price3", o.getPrice3());
		intent.putExtra("assumPrice", o.getAssumPrice());
		intent.putExtra("VIN", o.getCarVIN());
		intent.putExtra("type", o.getType());
		intent.putExtra("shouldpay", o.getShouldPay());
		intent.putExtra("msgs", (Serializable) o.getMsgs());
		startActivity(intent);
	}
}
